<?php
/*
 * @Author: wanzhengxin
 * @Date: 2021-04-01 21:58:34
 */


namespace app\server\controller;

use app\index\controller\Base;//application统一的模式，不要修改
use app\server\model\ServerOrder as ServerOrderModel;  //引入model.
class Serverorder extends Base
{

    public function get(){
        $res = new ServerOrderModel();
        $data=$this->request->param();
        $d=$res->with("servers,UserAddress,User")
            ->where($data['field'],$data['op'],$data['value'])
            ->where($data['field1'],$data['op1'],$data['value1'])
            ->where('is_complete',$data['is_complete'])
            ->page($data['page'])
            ->limit(20)
            ->order('cTime desc')
            ->select();
        return $d;
    }
    public function all(){
        $res = new ServerOrderModel();
        $data=$this->request->param();
        $d=$res->with("servers,UserAddress,doctor")
            ->where($data['field'],$data['op'],$data['value'])
            ->page($data['page'])
            ->limit(10)
            ->order('cTime desc')
            ->select();
        return $d;
    }
    //查询订单
    public function orderSearch(){
        $res = new ServerOrderModel();
        $data=$this->request->param();
        $a = $data['name'];
        $d = $res->hasWhere('UserAddress', function($query) use ( $a){
            $query->where('tel', 'like', '%'.$a.'%');
        })
            ->with("Servers,UserAddress,User")
            ->where($data['field'],$data['op'],$data['value'])
            ->order('cTime desc')
            ->select();
        return $d;
    }
    public function getOrderNum(){
        $res = new ServerOrderModel();
        $data=$this->request->param();
        $d = $res->where($data['field'],$data['op'],$data['value'])
            ->where('is_complete',$data['is_complete'])
            ->where('pay_status',$data['pay_status'])
            ->where('is_back',$data['is_back'])
            ->count();
        return $d;
    }
    public function update()
    {
        $data = $this->request->param();
        $res = new ServerOrderModel();
        return $res->updateModel($data);
    }
    public function delete(){
        $data = $this->request->param();
        $res = new ServerOrderModel();
        return $res->deleteModel($data);
    }
    public function save(){
        $res = new ServerOrderModel();
        $data = $this->request->param();
        $res->saveModel($data);
    }
    public function num(){
        $data = $this->request->param();
        $res =new ServerOrderModel();
        $d = $res->where($data['field'],$data['op'],$data['value'])
            ->count();
        return $d;
    }
}